"""Pod utilities"""

from ios_cov_manager.lib.cmd_util import execute_command


class PodError(Exception):
    """Exception raised for pod errors"""

    def __init__(self, message):
        super().__init__(message)
        self.message = message

    def __str__(self):
        return self.message


def execute_pod_command(command: str, ios_repo_dir: str):
    """Execute a pod command in the given directory"""

    _, err = execute_command(command=command, cwd=ios_repo_dir)
    if err:
        if "Error installing" in err:
            raise PodError(message=f"failed: {command}")


def pod_update(ios_repo_dir: str):
    """Execute 'pod update' command in the given directory"""

    execute_pod_command(command="pod update", ios_repo_dir=ios_repo_dir)


def pod_install_repo_update(ios_repo_dir: str):
    """Execute 'pod install --repo-update' command in the given directory"""

    execute_pod_command(command="pod install --repo-update", ios_repo_dir=ios_repo_dir)
